/*
 * 地址选择
 */
'use strict';
import React, { Component } from 'react';
import {
    View,
    Text,
    StyleSheet,
    Image,
    ListView,
    RefreshControl,
    ActivityIndicator,
    TouchableOpacity,
    Dimensions,
    Platform,
    Animated,
    PixelRatio,
    TouchableHighlight,
    AsyncStorage,
    Alert,
    ScrollView
} from 'react-native';

import NavTitle from '../component/NavTitle';

import List from 'antd-mobile/lib/list';
import Button from 'antd-mobile/lib/button';
import Modal from 'antd-mobile/lib/modal';
import Toast from 'antd-mobile/lib/toast';

const Item = List.Item;
const prompt = Modal.prompt;

import ChangePwd from './ChangePwd';
import Login from './Login';
import EditPerson from './EditPerson';

import XFetch from '../XFetch';

class Setting extends Component {
    constructor(props) {
        super(props)

        this.state = {
            signSta:true,
            userStatus:1,
            userName:'默认用户',
        }
    }

    componentDidMount(){
        AsyncStorage.getItem('username').then(data=>{
            if(data){
                this.setState({
                    username:data
                })
            }
        });
    }

    _login(){
        this.props.navigator.push({
            name:'EditPerson',
            component:EditPerson
        })
    }

    _changePwd(){
        this.props.navigator.push({
            name:'ChangePwd',
            component:ChangePwd
        })
    }

    _exitlogin(){
        AsyncStorage.removeItem('serveid');
        AsyncStorage.removeItem('shopid');
        this.props.navigator.push({
            name:'Login',
            component:Login
        })
    }

    render() {
        return (
            <View style={styles.container}>
                <NavTitle
                    title='设置'
                    leftButton = {true}
                    leftImg = {require('../imgs/left.png')}
                    leftText = {'返回'}
                    leftHander = {()=>{this.props.navigator.pop()}}
                    headColor = '#fbdc3a'
                />
                <ScrollView
                    showsVerticalScrollIndicator={false}
                >
                    <List style={styles.bgWhite}>
                        <Item arrow="horizontal" onClick={this._login.bind(this)} extra={this.state.username}>
                            <View style={{flexDirection:"row"}}>
                                <Image source={require('../imgs/set1.png')} style={{width:18,height:22}}/>
                                <Text style={{color:'#333',fontSize:18,marginLeft:10}}>修改昵称</Text>
                            </View>
                        </Item>
                        <Item arrow="horizontal" onClick={this._changePwd.bind(this)}>
                            <View style={{flexDirection:"row"}}>
                                <Image source={require('../imgs/set2.png')} style={{width:20,height:20}}/>
                                <Text style={{color:'#333',fontSize:18,marginLeft:10}}>修改密码</Text>
                            </View>
                        </Item>
                        <Item arrow="horizontal" onClick={this._exitlogin.bind(this)}>
                            <View style={{flexDirection:"row"}}>
                                <Image source={require('../imgs/me99.png')} style={{width:20,height:20}}/>
                                <Text style={{color:'#333',fontSize:18,marginLeft:10}}>退出登录</Text>
                            </View>
                        </Item>
                    </List>


                </ScrollView>
            </View>
        )
    }

}

const styles = StyleSheet.create({
    container: {
        backgroundColor: '#EEEEEF',
        flex: 1,
    },
    head:{
        padding:10,
        paddingLeft:15,
        flexDirection:'row',
        backgroundColor:'#F5F5F5',
        borderBottomWidth:1/PixelRatio.get(),
        borderColor:'#E8E8E8',
        marginBottom:10
    },
    bgWhite:{
        marginTop:15
    },
    logo:{
        width:68,
        height:68,
        borderRadius:34
    },
    detail:{
        flex:1,
        height:60,
        alignItems:'flex-start',
        justifyContent: 'center',
        paddingLeft:10
    },
    telphone:{
        color:'#666',
        fontSize:17
    },
    exit:{
        marginTop:20,
        paddingLeft:20,
        paddingRight:20
    }
});

export default Setting;
